package com.zyt.controller;

import com.zyt.pojo.Clazz;
import com.zyt.pojo.ClazzQueryParam;
import com.zyt.pojo.PageResult;
import com.zyt.pojo.Result;
import com.zyt.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
@Slf4j
public class ClazzController {
    @Autowired
    private ClazzService clazzService;

    /**
     * 添加班级
     *
     * @param clazz
     * @return
     */
    @PostMapping
    public Result add(@RequestBody Clazz clazz) {
        log.info("添加班级:{}", clazz);
        clazzService.save(clazz);
        return Result.success();
    }

    /**
     * 删除班级
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除员工:{}", id);
        clazzService.deleteById(id);
        return Result.success();
    }

    /**
     * 修改班级
     *
     * @param clazz
     * @return
     */
    @PutMapping
    public Result update(@RequestBody Clazz clazz) {
        log.info("修改班级:{}", clazz);
        clazzService.update(clazz);
        return Result.success();
    }

    /**
     * 查询班级
     *
     * @param
     * @return
     */
    @GetMapping
    public Result page(ClazzQueryParam clazzqueryParam) {
        log.info("分页查询:{}", clazzqueryParam);
        PageResult<Clazz> pageResult = clazzService.page(clazzqueryParam);
        return Result.success(pageResult);
    }
    /*
     *查询员工 id
     */


    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id) {
        log.info("查询员工:{}", id);
        Clazz clazz = clazzService.getInfo(id);
        return Result.success(clazz);
    }

    /*
    查询所有员工
     */
    @GetMapping("/list")
    public Result list() {
        log.info("查询所有员工");
        List<Clazz> list = clazzService.findAll();
        return Result.success(list);
    }


}
